{template 'common/header'}
{php echo $this -> set_tabbar($action);}
<!--地图begin-->
<script src="http://api.map.baidu.com/api?key=24ffad3855e675265336a4cfb46d32b4&v=1.1&services=true" type="text/javascript"></script>
<script src="http://api.map.baidu.com/getscript?v=1.1&ak=&services=true&t={TIMESTAP}" type="text/javascript" ></script>
<link href="http://api.map.baidu.com/res/11/bmap.css" rel="stylesheet" type="text/css">
<!--地图end-->
<div class="main">
        <form action="" method="post" onsubmit="return check();" class="form-horizontal form" enctype="multipart/form-data">
        <h4>{$title} - <a href="{php echo create_url('site/module', array('do' => 'SetRule', 'name' => 'icard'));}" style="font-size:0.8em">入口设置</a></h4>
		<table class="tb">
			<tr>
				<th><label for="">门店名称</label></th>
				<td>
                    <input type="text" name="title" value="{$reply['title']}" id="title" class="px" style="width:200px;" />
                    <div class="help-block">不超过30个字符</div>
				</td>
			</tr>
            <tr>
                <th><label for="">门店电话</label></th>
                <td>
                    <input type="text" name="tel" id="tel" value="{$reply['tel']}" class="px" style="width:200px;">
                </td>
            </tr>
            <tr>
                <th><label for="">门店地址</label></th>
                <td>
                    <input type="text" name="address" id="address" value="{$reply['address']}" class="px" style="width:200px;">
                </td>
            </tr>
            <tr>
                <th><label for="">登录消费密码</label></th>
                <td>
                    <input type="text" name="password" id="password" value="{$reply['password']}" class="px" style="width:200px;">
                    <div class="help-block">用户会员卡的消费密码和充值页的登录密码</div>
                </td>
            </tr>
            <tr>
                <th><label for="">会员充值密码</label></th>
                <td>
                    <input type="text" name="recharging_password" id="recharging_password" value="{$reply['recharging_password']}" class="px" style="width:200px;">
                    <div class="help-block">用于会员卡充值密码。低于16个字符</div>
                </td>
            </tr>
            <tr>
                <th><label for="">是否显示</label></th>
                <td>
                    <input type="radio" name="is_show" value="1" {if empty($reply)}checked="checked"{elseif $reply['is_show']==1}checked="checked"{/if} />显示
                    <input type="radio" name="is_show" value="0" {if empty($reply)}checked="checked"{elseif $reply['is_show']==0}checked="checked"{/if} />隐藏
                    <div class="help-block">是否在手机端显示前门店</div>
                </td>
            </tr>
            <tr>
                <th><label for="">门店简介</label></th>
                <td>
                    <textarea style="height:200px; width:535px;" class="span7 richtext-clone" name="content" cols="70" id="reply-add-text">{$reply['content']}</textarea>
                </td>
            </tr>
            <tr>
                <th><label for="">商家所在地区</label></th>
                <td>
                    <select name="location_p" id="location_p" class="location span3"></select>
                    <select name="location_c" id="location_c" class="location span3"></select>
                    <select name="location_a" id="location_a" class="location span3"></select>
                    <script type="text/javascript" src="./source/modules/icard/template/js/region_select.js"></script>
                    <script type="text/javascript">
                        var location_p = "{if !empty($reply['location_p'])}{$reply['location_p']}{else}广东省{/if}";
                        var location_c = "{if !empty($reply['location_c'])}{$reply['location_c']}{else}汕头市{/if}";
                        var location_a = "{if !empty($reply['location_a'])}{$reply['location_a']}{else}龙湖区{/if}";
                        new PCAS("location_p", "location_c", "location_a", location_p, location_c, location_a);
                    </script>
                </td>
            </tr>
            <tr>
                <th><label for="">经纬度</label></th>
                <td>
                    <div class="input-append">
                        <input type="text" id="place" class="input-xlarge valid" name="place" value="{$reply['place']}" data-rule-required="true">
                        <button class="btn" type="button" id="positioning" onclick="bmap.searchMapByAddress($('#place').val())">搜索</button>
                    </div>
                    <span class="maroon" style="color: #f30;margin-left: 5px;">注意：这个只是模糊定位，准确位置请地图上标注!</span>
                    <div id="l-map" style="overflow: hidden; position: relative; z-index: 0; background-image: url(http://api.map.baidu.com/images/bg.png);width: 600px; height: 500px;margin-top: 10px; color: rgb(0, 0, 0); text-align: left;"></div>
                    <div id="r-result">
                        <input type="text" id="lat" name="lat"> <input type="text" id="lng" name="lng">
                    </div>
                </td>
            </tr>
			<tr>
				<th></th>
				<td>
					<input name="submit" type="submit" value="提交" class="btn btn-primary span3">
					<input type="hidden" name="token" value="{$_W['token']}" />
				</td>
			</tr>
		</table>
	</form>
</div>

<script type="text/javascript">
        function check() {
            if($.trim($('#title').val()) == '') {
                message('没有输入门店名称.', '', 'error');
                return false;
            }
            if($.trim($('#tel').val()) == '') {
                message('没有输入门店电话.', '', 'error');
                return false;
            }
            if($.trim($('#address').val()) == '') {
                message('没有输入门店地址.', '', 'error');
                return false;
            }
            return true;
        }
        </script>
<script type="text/javascript">
    kindeditor($('.richtext-clone'));
    kindeditorUploadBtn($('#btnlogo'));
</script>

<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.4"></script>
<script type="text/javascript" src="http://api.map.baidu.com/getscript?v=1.4&ak=&services=&t=20140102035142"></script>
<script type="text/javascript">
    $(function(){
        $(".location").change(function(){
            bmap.searchMapByPCD();
        });
    });
    new PCAS("location_p", "location_c", "location_a", location_p, location_c, location_a);
    var bmap = {
        'option' : {
            'lock' : false,
            'container' : 'l-map',
            'infoWindow' : {'width' : 250, 'height' : 100, 'title' : ''},
            'point' : {'lng' : "{if $reply['lng']!='0.0000000000' && !empty($reply['lng'])}{$reply['lng']}{else}116.735049{/if}", 'lat' : "{if $reply['lat']!='0.0000000000' && !empty($reply['lat'])}{$reply['lat']}{else}23.367896{/if}"}
        },
        'init' : function(option) {
            var $this = this;
            $this.option = $.extend({},$this.option,option);

            $this.option.defaultPoint = new BMap.Point($this.option.point.lng, $this.option.point.lat);
            $this.bgeo = new BMap.Geocoder();
            $this.bmap = new BMap.Map($this.option.container);
            $this.bmap.centerAndZoom($this.option.defaultPoint, 15);
            $this.bmap.enableScrollWheelZoom();
            $this.bmap.enableDragging();
            $this.bmap.enableContinuousZoom();
            $this.bmap.addControl(new BMap.NavigationControl());
            $this.bmap.addControl(new BMap.OverviewMapControl());
            //添加标注
            $this.marker = new BMap.Marker($this.option.defaultPoint);
            $this.marker.setLabel(new BMap.Label('请您移动此标记，选择您的坐标！', {'offset':new BMap.Size(10,-20)}));
            $this.marker.enableDragging();
            $this.bmap.addOverlay($this.marker);
            //$this.marker.setAnimation(BMAP_ANIMATION_BOUNCE);
            $this.showPointValue($this.marker.getPosition());
            //拖动地图事件
            $this.bmap.addEventListener("dragging", function() {
                $this.setMarkerCenter();
                $this.option.lock = false;
            });
            //缩入地图事件
            $this.bmap.addEventListener("zoomend", function() {
                $this.setMarkerCenter();
                $this.option.lock = false;
            });
            //拖动标记事件
            $this.marker.addEventListener("dragend", function (e) {
                $this.showPointValue();
                $this.showAddress();
                $this.bmap.panTo(new BMap.Point(e.point.lng, e.point.lat));
                $this.option.lock = false;
                $this.marker.setAnimation(null);
            });
        },
        'searchMapByAddress' : function(address) {
            var $this = this;
            $this.bgeo.getPoint(address, function (point) {
                if (point) {
                    $this.showPointValue();
                    $this.showAddress();
                    $this.bmap.panTo(point);
                    $this.setMarkerCenter();
                }
            });
        },
        'searchMapByPCD' : function(address) {
            var $this = this;
            $this.option.lock = true;
            $this.searchMapByAddress($('#location_p').val()+$('#location_c').val()+$('#location_a').val());
        },
        'setMarkerCenter' : function() {
            var $this = this;
            var center = $this.bmap.getCenter();
            $this.marker.setPosition(new BMap.Point(center.lng, center.lat));
            $this.showPointValue();
            $this.showAddress();
        },
        'showPointValue' : function() {
            var $this = this;
            var point = $this.marker.getPosition();
            $('#lng').val(point.lng);
            $('#lat').val(point.lat);
        },
        'showAddress' : function() {
            var $this = this;
            var point = $this.marker.getPosition();
            $this.bgeo.getLocation(point, function (s) {
                if (s) {
                    $('#place').val(s.address);
                    if (!$this.option.lock) {
                        new PCAS("location_p", "location_c", "location_a", s.addressComponents.province, s.addressComponents.city, s.addressComponents.district);
                    }
                }
            });
        }
    };
    $(function(){
        var option = {};
        bmap.init(option);
    });</script>
{template 'common/footer'}
